package com.chagee.store.operation.server.service;

import com.chagee.base.utils.PaginationData;
import com.chagee.base.utils.PaginationRequest;
import com.chagee.lark.anno.ExceptionLarkNotice;
import com.chagee.lark.enums.UrgentTypeEnum;
import com.chagee.base.utils.*;
import com.chagee.store.operation.api.enums.*;
import com.chagee.store.operation.api.request.*;
import com.chagee.store.operation.server.facade.WorkOrderFacade;
import com.chagee.store.operation.server.model.param.BatchUpdatePenalizeParam;
import com.chagee.store.operation.server.model.param.WorkOrderDeviceParam;
import com.chagee.store.operation.server.model.param.WorkOrderDetailRequest;
import com.chagee.store.operation.server.model.vo.BatchUpdatePenalizeVO;
import com.chagee.store.operation.api.response.StoreWorkOrderDeviceResponse;
import com.chagee.store.operation.api.response.WorkOrderResponse;
import com.chagee.store.operation.server.model.vo.mapVO.DictVo;
import com.chagee.store.operation.server.model.vo.mapVO.DictVoInt;
import com.chagee.store.operation.server.model.vo.mapVO.WorkOrderMapVo;
import com.chagee.storeManagement.api.event.enums.DocumentTyEnum;
import com.chagee.storeManagement.api.event.enums.StoreCategoryEnum;
import com.chagee.storeManagement.api.event.response.BasePageResponse;
import com.chagee.storeManagement.api.event.response.QueryStoreOperateRecordResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class WorkOrderService {

	@Resource
	private WorkOrderFacade workOrderFacade;

	/**
	 * 门店数据字典
	 *
	 * @return 数据字典
	 */
	public WorkOrderMapVo dict() {
		WorkOrderMapVo workOrderMapVo = new WorkOrderMapVo();
		//单据状态
		List<DictVoInt> WorkOrderStatus = Arrays.stream(StoreWorkOrderStatusEnum.values()).map(StoreWorkOrderStatusEnum -> {
			DictVoInt vo = new DictVoInt();
			vo.setValue(StoreWorkOrderStatusEnum.getType());
			vo.setLabel(StoreWorkOrderStatusEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		//店铺类型
		List<DictVo> storeCategoryType = Arrays.stream(StoreCategoryEnum.values()).map(StoreCategoryEnum -> {
			DictVo vo = new DictVo();
			vo.setValue(StoreCategoryEnum.getType());
			vo.setLabel(StoreCategoryEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		//单据类型
		List<DictVoInt> DocumentTy = Arrays.stream(DocumentTyEnum.values()).map(DocumentTyEnum -> {
			DictVoInt vo = new DictVoInt();
			vo.setValue(DocumentTyEnum.getType());
			vo.setLabel(DocumentTyEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		List<DictVo> orderAcceptanceResult = Arrays.stream(OrderAcceptanceEnum.values()).map(s -> {
			DictVo vo = new DictVo();
			vo.setValue(s.getType());
			vo.setLabel(s.getDesc());
			return vo;
		}).collect(Collectors.toList());
		List<DictVo> orderAcceptanceType = Arrays.stream(OrderAcceptanceTypeEnum.values()).map(s -> {
			DictVo vo = new DictVo();
			vo.setValue(s.getType());
			vo.setLabel(s.getDesc());
			return vo;
		}).collect(Collectors.toList());
		List<DictVo> orderAppealType = Arrays.stream(OrderAppealTypeEnum.values()).map(s -> {
			DictVo vo = new DictVo();
			vo.setValue(s.getType());
			vo.setLabel(s.getDesc());
			return vo;
		}).collect(Collectors.toList());
		//供应商
		List<String> workApiSoaResponse = workOrderFacade.distinctSupplier();
		//单据状态
		workOrderMapVo.setDocumentStatusDict(WorkOrderStatus);
		//店铺类型
		workOrderMapVo.setStoreCategoryDict(storeCategoryType);
		//供应商
		workOrderMapVo.setSupplier(workApiSoaResponse);
		workOrderMapVo.setDocumentTyDict(DocumentTy);
		workOrderMapVo.setOrderAcceptanceResult(orderAcceptanceResult);
		workOrderMapVo.setOrderAcceptanceType(orderAcceptanceType);
		workOrderMapVo.setOrderAppealType(orderAppealType);
		return workOrderMapVo;
	}

	/**
	 * 获取工单的交接的设备信息
	 *
	 * @param workOrderDeviceParam 工单编号
	 * @return 交接设备对象
	 */
	public StoreWorkOrderDeviceResponse getWorkOrderDevice(WorkOrderDeviceParam workOrderDeviceParam) {
		return workOrderFacade.getWorkOrderDevice(workOrderDeviceParam);
	}

	/**
	 * 开早打样工单详情
	 *
	 * @param request 工单编号
	 * @return 工单信息
	 */
	public WorkOrderResponse queryDetail(WorkOrderDetailRequest request) {
		return workOrderFacade.queryDetail(request);
	}

	/**
	 * 工单表查询
	 */
	public PaginationData<WorkOrderResponse> query(PaginationRequest<WorkOrderRequest> request){
		return workOrderFacade.query(request);
	}

	/**
	 * 导出门店打烊工单
	 */
	public void export(WorkOrderRequest taskListParam, HttpServletRequest request, HttpServletResponse response, ModelMap map){
		workOrderFacade.export(taskListParam,request,response,map);
	}

	public Boolean penalizeMoney(OrderPenalizeMoneyRequest request){
		return workOrderFacade.penalizeMoney(request);
	}

	public BatchUpdatePenalizeVO batchUpdatePenalizeMoney(BatchUpdatePenalizeParam request){
		return workOrderFacade.batchUpdatePenalizeMoney(request);
	}


	public HttpResponse<Boolean> handleAppeal(StoreHandleAppealRequest request){
		return workOrderFacade.handleAppeal(request);
	}

	public BasePageResponse<QueryStoreOperateRecordResponse> queryOperateRecordPage(PaginationRequest<WorkOrderRecordRequest> request){
		return workOrderFacade.queryOperateRecordPage(request);
	}
}
